package com.molin.networkTest.socketTest.tcpTest.Demo4;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.*;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket=new ServerSocket(8888);

        ThreadPoolExecutor pool=new ThreadPoolExecutor(
                5,//核心线程数
                10,//线程总数
                60,//线程空闲时间
                TimeUnit.SECONDS,//线程空闲时间的单位
                new ArrayBlockingQueue<>(5),//存储线程的队列
                new ThreadPoolExecutor.AbortPolicy()//线程策略
        );

        //使用线程池
        while (true){
            Socket socket=serverSocket.accept();
            CopyfileRunnable copyfileRunnable=new CopyfileRunnable(socket);
//            new Thread(copyfileRunnable).start();
            pool.submit(copyfileRunnable);
        }

//socket.close();
    }
}
